package com.qf.controller;

import com.qf.pojo.Role;
import com.qf.service.RoleService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    RoleService roleService;

    @GetMapping("/queryAllRole")
    public ResultMsg queryAllRole(@RequestParam(required = false, defaultValue = "1", name = "page") Integer page, @RequestParam(name = "limit", required = false, defaultValue = "10") Integer limit) {
        ResultMsg resultMsg = roleService.queryAllRole(page, limit);
        return resultMsg;
    }

    @GetMapping("/queryOneRole")
    public ResultMsg queryOneRole(@RequestParam(required = false) Integer roleId) {
        ResultMsg resultMsg = roleService.queryOneRole(roleId);
        return resultMsg;
    }

    @PutMapping("/updateRole")
    public ResultMsg updateRole(@RequestBody Role role) {
        ResultMsg resultMsg = roleService.updateRole(role);
        return resultMsg;
    }

    @PutMapping("/insertRole")
    public ResultMsg insertRole(@RequestBody Role role) {
        ResultMsg resultMsg = roleService.insertRole(role);
        return resultMsg;
    }
}
